﻿using UnityEngine;
using System.Collections;

public class EnemySpawn : MonoBehaviour {

    public GameObject enemy0;
    public GameObject enemy1;
    public GameObject enemy2;
    public float enemyDensity = 1;
    private GameObject enemies;

    void Awake()
    {
        enemies = GameObject.Find("Enemies");
    }

    // Use this for initialization
    void Start () {
        InvokeRepeating("CreateEnemy", 0, enemyDensity);
	}
	
	// Update is called once per frame
	void Update () {
	    
	}

    void CreateEnemy()
    {
        int isCreate = Random.Range(0, 15);
        float offset = Random.Range(-0.3f, 0.3f);
        GameObject enemy = null;
        if (isCreate >= 0 && isCreate < 9)
        {
            enemy = Instantiate(enemy0, transform.position + new Vector3(offset, offset,0), Quaternion.identity) as GameObject;
        }
        else if(isCreate >= 9 && isCreate < 14)
        {
            enemy = Instantiate(enemy1, transform.position + new Vector3(offset, offset, 0), Quaternion.identity) as GameObject;
        }
        else
        {
            enemy = Instantiate(enemy2, transform.position + new Vector3(offset, offset, 0), Quaternion.identity) as GameObject;
        }
        enemy.transform.parent = enemies.transform;
    }
} 
